package com.geek.shiro;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * 会话管理器，负责Shiro使用过程中的Session会话管理,继承DefaultWebSessionManager
 */
public class CustomSessionManager extends DefaultWebSessionManager {
    @Override
    protected Serializable getSessionId(ServletRequest servletRequest, ServletResponse response) {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String sessionId = request.getHeader("X-CskaoyanMarket-Token");
        if (sessionId != null && !"".equals(sessionId)) {
            return sessionId;
        }
        return super.getSessionId(servletRequest, response);
    }

}
